package com.dyz.leetcode._10_slidingWindow;

public class _845_longestMountain {
    public int longestMountain(int[] arr) {
        int n = arr.length;
        int ans = 0;
        int left = 0;
        while (left+2<n){
            int right = left + 1;
            if (arr[left] < arr[right]) {
                // 找到最高点
                while (right + 1 < n && arr[right] < arr[right + 1]) {
                    right++;
                }
                //
                if (right + 1 < n && arr[right] > arr[right + 1]) {
                    // 找到最低点
                    while (right + 1 < n && arr[right] > arr[right + 1]) {
                        right++;
                    }
                    ans = Math.max(ans, right - left + 1);
                }else {
                    right++;
                }
            }
            left = right;
        }
    return ans;
    }
}
